package com.sql;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
public class MySQL {
	

	public static  int Query(String name,String pass){
		
				 int flag=0;
				try {
					Connection con = getConnection();
					Statement sql_statement = con.createStatement();
					String query = "select * from user where name='"+name+"' and password='"+pass+"'";
					
					ResultSet result = sql_statement.executeQuery(query);
					
					while(result.next()){
						
						flag=1;
					}
					sql_statement.close();
					con.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					System.out.println(e);
					flag=0;	
				}
			
				return flag;
				
}
	public static Connection getConnection() throws SQLException, java.lang.ClassNotFoundException {

		Class.forName("com.mysql.jdbc.Driver");

		String url = "jdbc:mysql://localhost:3306/emergency";
		String username = "root";
		String password = "liuxingyu";

		Connection con = (Connection) DriverManager.getConnection(url, username, password);
		return con;
	}
	
}
